package com.yuexiang.melodyhub.authserver.handler;

import com.yuexiang.melodyhub.authserver.handler.context.LoginContext;
import com.yuexiang.melodyhub.common.constant.UsualConstant.BizCodeConstant;
import com.yuexiang.melodyhub.common.constant.user.UserStatus;
import com.yuexiang.melodyhub.common.dto.user.UserFindWithRolesByUsername.response.UserFindWithRolesByUsernameResponse;
import com.yuexiang.melodyhub.common.exception.RequestArgumentException;
import com.yuexiang.melodyhub.common.handler.AbstractValidationHandler;
import org.springframework.stereotype.Component;

@Component
public class UserStatusValidationHandler extends AbstractValidationHandler<LoginContext> {
    @Override
    public void handler(LoginContext content) {
        UserFindWithRolesByUsernameResponse userFindResponse = content.getUserFindResponse();

        if (userFindResponse.getStatus().equals(UserStatus.STATUS_BANDED.getStatus()))
            throw new RequestArgumentException(BizCodeConstant.Msg.U_IS_BANDED);
        if (userFindResponse.getStatus().equals(UserStatus.STATUS_PENDING.getStatus()))
            throw new RequestArgumentException(BizCodeConstant.Msg.U_IS_PENDING);
        handlerNext(content);
    }
}
